package com.bjsdzk.collector.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.math.BigDecimal;
import java.util.Date;

@Document(collection = "RealTimeData")
public class RealTimeData {

    @Id
    private String _id;

    private String des;
    private int type;
    private String portAndaddr;
    private String deviceId;
    private String unit;
    private double value;

    private Date createdAt;
    private String dataSource;

    
    public RealTimeData(String des, int type, String unit, double value, Date createdAt,String deviceId) {
		super();
		this.des = des;
		this.type = type;
		this.unit = unit;
		this.value = value;
		this.createdAt = createdAt;
		this.deviceId = deviceId;
	}
    
	public RealTimeData(String des, int type, String unit, double value, Date createdAt,String deviceId, String dataSource) {
		super();
		this.des = des;
		this.type = type;
		this.unit = unit;
		this.value = value;
		this.createdAt = createdAt;
		this.deviceId = deviceId;
		this.dataSource = dataSource;
	}




	public RealTimeData() {
		super();
	}
	
	public String getDataSource() {
		return dataSource;
	}


	public void setDataSource(String dataSource) {
		this.dataSource = dataSource;
	}


	public String get_id() {
        return _id;
    }

    public void set_id(String _id) {
        this._id = _id;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

 
    public String getPortAndaddr() {
		return portAndaddr;
	}

	public void setPortAndaddr(String portAndaddr) {
		this.portAndaddr = portAndaddr;
	}

	public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public double getValue() {
        return value;
    }

    public void setValue(double value) {
        BigDecimal bigDecimal = new BigDecimal(value);
        this.value = bigDecimal.setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    @Override
    public RealTimeData clone(){
        RealTimeData rt = null;
        try {
            rt = (RealTimeData) super.clone();
        }catch (CloneNotSupportedException cnse){
            cnse.printStackTrace();
        }
        return rt;
    }

	@Override
	public String toString() {
		return "RealTimeData [_id=" + _id + ", des=" + des + ", type=" + type + ", portAndaddr=" + portAndaddr
				+ ", deviceId=" + deviceId + ", unit=" + unit + ", value=" + value + ", createdAt=" + createdAt
				+ ", dataSource=" + dataSource + "]";
	}
    
}
